<script lang="ts">
	import { Any } from '$lib/api/proto/google/protobuf/any';
	import { RESOURCE_TYPE } from '$lib/api/proto/resource_api';
	import type { NodeInfo } from '$lib/api/proto/roadmap_data_api';
	import { InnerResourceData } from '$lib/api/proto/roadmap_data_type_api';
	import CardResourceState from './CardResourceState.svelte';
	import ExamResourceState from './ExamResourceState.svelte';

	interface Props {
		nodeInfo: NodeInfo;
	}
	const props: Props = $props();

	let resourceInfo = $state(null as InnerResourceData | null);

	async function loadresourceInfo() {
		if (props.nodeInfo.content == undefined) {
			return;
		}

		const nodeContentData = Any.unpack(props.nodeInfo.content, InnerResourceData);
		resourceInfo = nodeContentData;
	}

	loadresourceInfo();
</script>

{#if resourceInfo != null}
	{#if resourceInfo.resourceType == RESOURCE_TYPE.RESOURCE_TYPE_CARD}
		<CardResourceState />
	{:else if resourceInfo.resourceType == RESOURCE_TYPE.RESOURCE_TYPE_EXAM}
		<ExamResourceState />
	{/if}
{/if}
